home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / ATTACKE.CPP < prev    next >
C/C++ Source or Header  |  1994-06-16  |  2KB  |  61 lines

  1. // Copyright 1993 by Jon Dart.  All Rights Reserved.
  2.  
  3. #include "attacke.h"
  4. #include "bearing.h"
  5. #include "util.h"
  6. #include "constant.h"
  7. #include <assert.h>
  8.  
  9. int attack_estimate( const Board &board, const ExtendedMove &emove )
  10. {
  11.     ColorType my_side = emove.PieceMoved().Color();
  12.     ColorType side = my_side;
  13.     Square square = emove.DestSquare();
  14.     Square piece_square = emove.StartSquare();
  15.     Piece::PieceType on_square = board[square].Type();
  16.     Piece::PieceType attacker = board[piece_square].Type();
  17.     int score_count = 0;
  18.     int score_list[10];
  19.     int swap_score = 0;
  20.     int gain;
  21.     // make copies of the attack info for the square:
  22.     Attack_Entry my_atcks(board.get_attacks(square,side));
  23.     Attack_Entry opp_atcks(board.get_attacks(square,OppositeColor(side)));
  24.     my_atcks.remove_attack(attacker);
  25.     do
  26.     {
  27.     gain = Piece::Value(on_square);
  28.     if (attacker == Piece::Pawn &&
  29.         square.Rank(side) == 8)
  30.     {
  31.         gain += Piece::Value(Piece::Queen) - Piece::Value(Piece::Pawn);
  32.     }
  33.     if (side == my_side)
  34.         swap_score += gain;
  35.     else
  36.         swap_score -= gain;
  37.     score_list[score_count++] = swap_score;
  38.     side = OppositeColor(side);
  39.     on_square = attacker;
  40.         if (side == my_side)
  41.        attacker = my_atcks.remove_min_attacker();
  42.         else
  43.        attacker = opp_atcks.remove_min_attacker();
  44.     } while (attacker != Piece::Empty);
  45.     if (score_count > 1 && score_count % 2 == 0)
  46.     {
  47.         // last capture is by other side, can't avoid it
  48.     score_list[score_count-2] = score_list[score_count-1];
  49.     --score_count; 
  50.     }
  51.     int i = score_count;
  52.     while (i >= 3)
  53.     {
  54.     int max_score = Util::Max(score_list[i-1],score_list[i-2]);
  55.     if (max_score < score_list[i-3])
  56.         score_list[i-3] = max_score;
  57.     i -= 2;
  58.     }
  59.     return score_list[0];
  60. }
  61.